package com.benyi.util;

import java.net.NetworkInterface;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;

public class Stick {
	
	public static List<String> getSticks() {
		List<String> ls = new ArrayList<String>(); 
		try {
			Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
			StringBuilder sb = new StringBuilder();
			while(networkInterfaces.hasMoreElements()) {
	            NetworkInterface interface1 = networkInterfaces.nextElement(); 
	            if (interface1.getParent() == null && 
	            		interface1.getInetAddresses() != null && 
	            		interface1.getHardwareAddress() != null){  
	                byte[] btMac = interface1.getHardwareAddress();
	                for (int i = 0; i < btMac.length; i++) {
	                	if(i>0) {
	                		sb.append(":");
	                	}
	                	String m  = Integer.toHexString(btMac[i] & 0xff).toUpperCase(); 
	                	sb.append(m);
	                } 
	                ls.add(sb.toString());
	                sb.setLength(0);
	            }
	        }
		}catch(Exception e) {
			e.printStackTrace();
		} 
        return ls;
	}
	
	public static void main(String []args) {
		List<String> ls = getSticks();
		for(int i=0;i<ls.size();i++) {
			System.out.println(ls.get(i));
		}
		
		System.out.println(Integer.valueOf("A1", 16));
	}
}
